package org.spring.boot.example.dds;

import java.lang.reflect.Method;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;

public class DynamicDataSourcePointcut implements Pointcut{
	@Override
	public MethodMatcher getMethodMatcher() {
		return new MethodMatcher() {

			@Override
			public boolean matches(Method method, Class<?> targetClass, Object... args) {
				return matches(method, targetClass);
			}

			@Override
			public boolean matches(Method method, Class<?> targetClass) {
				return method.isAnnotationPresent(DataSourceName.class)
						|| targetClass.isAnnotationPresent(DataSourceName.class);
			}

			@Override
			public boolean isRuntime() {
				return false;
			}
		};
	}

	@Override
	public ClassFilter getClassFilter() {
		return ClassFilter.TRUE;
	}
}
